//index.js
//获取应用实例
const app = getApp()
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');

Page({
  data: {
    message: '淘淘领',
    app_token:'获取app_token',
    security_code:'获取sign签名'
  },  

  taotaoDemo: function (e) {
    const self = this;
    const data = {
        //测试环境默认设置的
        page: '{"page_size":"15","page_no":"1"}',
        service:'psGoods.consumer.freeGetGoodsListPageFind',
        params:'{}',
        app_token: self.data.app_token,
      }  

    var sign = util.getSign(data, self.data.security_code);
    
    console.log(sign);
    data.sign = sign;

    api.getGoodsList({
      data,
      success: (res) => {
        console.log(res.data);
        //self.setDate(res.data);
      }
    })
  },


  tapName:function (e){
    const self = this;
    const data = {
      //测试环境默认设置的
      app_id: 'bcc1cf2e-b376-11e5-921c-fcaa1490ccaf',
      private_key: '690b98fcb37711e5921cfcaa1490ccaf717130d1b37711e5921cfcaa1490ccaf'
      };
    api.getLogin({
      data,
      success: (res) => {
        console.log(res.data);
        //self.setDate(res.data);
        const app_token = res.data.data.app_token;
        const security_code = res.data.data.security_code;
        self.setData({
          app_token: app_token,
          security_code: security_code
        });
      }
    })
  },

  shoplist: function (e) {
    const ds = e.currentTarget.dataset;
    wx.navigateTo({
      //url: `../trip/trip?id=${ds.id}&name=${ds.name}`,
      url: `../buy/shoplist/shoplist`,
    });
  },

  viewTrip: function(e) {
    const ds = e.currentTarget.dataset;
    wx.navigateTo({
      //url: `../trip/trip?id=${ds.id}&name=${ds.name}`,
      //url: `../buy/list/list`,
      url: `../buy/goodslist/goodslist`,
    });
  },

  nearshoplist: function (e) {
    const ds = e.currentTarget.dataset;
    wx.navigateTo({
      //url: `../trip/trip?id=${ds.id}&name=${ds.name}`,
      url: `../buy/nearshoplist/nearshoplist`,
    });
  }

  
})
